﻿namespace Arms.Application.Modules.Security
{
    using Arms.Framework.Security;
    using System;
    using System.Linq;
    using System.Security.Principal;

    public class ArmsUser : IUser
    {
        private IIdentity _identity;

        public int UserID { get; set; }
        public int UserClassID { get; set; }
        public string UserName { get; set; }
        public string EmailAddress { get; set; }
        public string[] Roles { get; set; }

        public IIdentity Identity
        {
            get { return _identity; }
        }

        public ArmsUser(IIdentity identity)
        {
            _identity = identity;
        }

        public bool IsInRole(string role)
        {
            return this.Roles.Contains(role);
        }
        
        /// <summary>
        /// Determines whether this user is in an anonymous state.
        /// </summary>
        public bool HasIdentity
        {
            get { return this.UserID <= 0 || _identity != null; }
        }
    }
}
